layui.use(['layer', 'form', 'admin', 'laydate', 'ax','selectPlus'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var selectPlus = layui.selectPlus;
    var userId = Feng.getUrlParam("userId");
    // var values ;
    // new $ax(Feng.ctxPath + "/mgr/relationUserName?userId="+userId, function (data){
    //     values = data.data.split(",");
    // }).start();
// 多选
//     var agentList = selectPlus.render({
//         el: '#agentId',
//         url: Feng.ctxPath + "/mgr/userAgentList",
//         valueName: "name",
//         values: values,
//         valueSeparator: ","
//     });

    new $ax(Feng.ctxPath + "/mgr/userAgentList",
        function (data) {
            var str = '<option value="">请选择</option>';
            data.forEach(function (d){
                str=str+"<option value="+d.value+" >"+d.name+"</option>";
            });
            $("#agentId").html(str);
            form.render();
        }).start();
    new $ax(Feng.ctxPath + "/mgr/relationUserInfo?userId="+userId, function (data){
        form.val('userForm', data.data);
    }).start();
    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        // var agentId = "";
        // var obj = agentList.getChecked().data.forEach(e=>{
        //     agentId  += e.value + ",";
        // });
        // data.field.agentIds = agentId

        data.field.userId = userId;
        var ajax = new $ax(Feng.ctxPath + "/mgr/relationUser", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });
});